/*
Copyright(c) 2008 Jari Kemppinen <jari@viddem.com>

This example was built upon the PureMVC Framework by Cliff Hall.
http://www.puremvc.org
This example uses the Java PureMVC Framework Version 0.2

Please contribute to the PureMVC community.

License
-------
Your reuse is governed by the Creative Commons Attribution 3.0 license.
 */

package org.lbroussal.client.view.components;

import org.lbroussal.client.view.LoginScreenMediator;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class LoginScreen extends Composite {

    private Button submitCommand;

    private TextBox usernameInput;

    private TextBox passwordInput;

    private LoginScreenMediator mediator;

    public LoginScreen(LoginScreenMediator mediator) {
        this.mediator = mediator;
        VerticalPanel verticalPanel = new VerticalPanel();
        initWidget(verticalPanel);
    }

    public void loginFail() {
        Window.alert("Please enter puremvc as password! ");
    }

    public void showLoginBox() {
        final DialogBox dialogBox = new DialogBox();
        dialogBox.setText("Login");
        dialogBox.setAnimationEnabled(true);

        VerticalPanel dialogVPanel = new VerticalPanel();
        dialogVPanel.setWidth("100%");

        HorizontalPanel horizontalPanel = new HorizontalPanel();
        horizontalPanel.add(new Label("Username:"));
        usernameInput = new TextBox();
        horizontalPanel.add(usernameInput);

        HorizontalPanel horizontalPanel1 = new HorizontalPanel();
        horizontalPanel1.add(new Label("Password:"));
        passwordInput = new TextBox();
        horizontalPanel1.add(passwordInput);

        submitCommand = new Button("Submit");
        submitCommand.addClickListener(new ClickListener() {

            public void onClick(Widget sender) {
                LoginScreen.this.mediator.SUBMITLOGIN(usernameInput.getText(), passwordInput.getText());
            }
        });

        dialogVPanel.add(horizontalPanel);
        dialogVPanel.add(horizontalPanel1);
        dialogVPanel.add(submitCommand);

        dialogBox.setWidget(dialogVPanel);

        dialogBox.center();
        dialogBox.show();
    }

}